package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.User;
import com.cskaoyan.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zhangminghui
 * @date 2022/8/6
 */
@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    UserService userService;

    @RequestMapping("add")
    public BaseRespVo add(String username, String password, Integer age, String birthday) {
        User user = new User();
        user.setUsername(username);
        user.setPassword(password);
        user.setAge(age);
        user.setBirthday(birthday);
        userService.addUser(user);
        Integer newId = user.getId();
        return BaseRespVo.ok("id:" + newId + " username:" + username + " password:" + password + " age:" + age + " birthday:" + birthday);
    }

    @RequestMapping("select")
    public List<User> select(String username) {
        List<User> userList = userService.selectUserByUsername(username);
//        if (userList != null && userList.size() != 0 ) {
//            for (User user : userList) {
//                return BaseRespVo.ok("username:" + user.getUsername() + " password:" + user.getPassword() + " age:" + user.getAge() + " birthday:" + user.getBirthday());
//            }
//        }
//        return BaseRespVo.ok("没有查询到相关用户");
        return userList;
        // 也可以返回 List<BaseRespVo>，相应方法的形参也要改一下
    }
    //wjdsg DO
    @RequestMapping("hello")
    public BaseRespVo hello(){
        return BaseRespVo.ok("Hello！！");
    }
    //hsdsg Do
    @RequestMapping("bye")
    public BaseRespVo bye(){
        return BaseRespVo.ok("bye！！");
    }
     //mh Do
    @RequestMapping("mh")
    public BaseRespVo byeByMh(){
        return BaseRespVo.ok("bye！！");
    }

    // zmh Do
    @RequestMapping("zmh")
    public BaseRespVo zmh(){
        return BaseRespVo.ok("kunkun chu xin ge le");
    }


    //cc Do
    @RequestMapping("Hi")
    public BaseRespVo hi(){
        return BaseRespVo.ok("Hi");
    }

    @RequestMapping("zty")
    public BaseRespVo zty(){
        return BaseRespVo.ok("是兄弟就来看我。");

    }

    // cbj Do
    @RequestMapping("sleep")
    public BaseRespVo sleep(){
        return BaseRespVo.ok("sleep");
    }


}
